package org.remixlab.gnutopic.client;

import java.awt.Color;

import processing.core.PGraphics;

public class CircleButton {
	
	//coordenada s donde se pintará el botón
	private int x;
	private int y;
	private int diameter;
	
	private Color color;
	private Color selectedColor;
	
	private boolean selected;
	
	private PGraphics parent;
	
	public CircleButton(int x, int y, int diameter){
		
		this.x = x;
		this.y = y;
		this.diameter = diameter;
		
		this.color = new Color(255, 255, 255);
		this.selectedColor = new Color(255, 0, 0);
		
		this.selected = false;
	}
	
	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}

	public int getDiameter() {
		return diameter;
	}

	public void setDiameter(int diameter) {
		this.diameter = diameter;
	}

	public PGraphics getParent() {
		return parent;
	}

	public void setParent(PGraphics parent) {
		this.parent = parent;
	}

	public Color getColor() {
		return color;
	}

	public void setColor(Color color) {
		this.color = color;
	}

	public Color getSelectedColor() {
		return selectedColor;
	}

	public void setSelectedColor(Color selectedColor) {
		this.selectedColor = selectedColor;
	}

	public boolean isSelected() {
		return selected;
	}

	public void setSelected(boolean selected) {
		this.selected = selected;
	}

	/**
	 * indica si el x1, y1 se encuentran dentro del circulo (si el mouse esta encima del circulo)
	 * @param x1
	 * @param y1
	 * @return
	 */
	public boolean overCircle(int x1, int y1) 
	{
	  float disX = x1 - x;
	  float disY = y1 - y;
	  if(Math.sqrt(Math.pow(disX,2) + Math.pow(disY,2)) < diameter/2 ) {
	    selected = true;
	  } else {
		  selected = false;
	  }
	  
	  return selected;
	}
	
	/**
	 * Dibuja el circulo..
	 */
	public void draw(){
		if(parent!=null){
			if(!selected){
				parent.fill(color.getRed(), color.getGreen(), color.getBlue());
				parent.stroke(selectedColor.getRed(), selectedColor.getGreen(), selectedColor.getBlue());
			}else{
				parent.fill(selectedColor.getRed(), selectedColor.getGreen(), selectedColor.getBlue());
				parent.stroke(color.getRed(), color.getGreen(), color.getBlue());
			}
			
			//dibujo la elipse...
			parent.ellipse(x , y, diameter, diameter);
		}
	}
}
